
%include 'C:\HSPH\manuscripts\Flourishing and work outcomes\Programs\Revision\Flourishing_and_work_230828.sas'; *call in the datastep codes;


*COMPLETE-CASE ANALYASES*;

**********************************************************************************************
     1. Indiviudal 2018 flourishing dimensions and 2019 work outcomes, without adjustment for each other
********************************************************************************************** ;

*1. emotional health;
Data complete;
set wellbeing;

if nmiss (of emot_hlth_dim2_H2018 phys_hlth_dim_H2018 social_WB_H2018 char_str_H2018 financ_WB2_H2018 purpose_dim2_H2018 
             race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
             elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
             work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018 
             distracted2018_r jobsatis2018 w_productive2018)>0 then delete;

%macro linear(outcome);
proc glm data=complete;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= emot_hlth_dim2_H2018  
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm; 
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

data estimate2;
length outcome $50.;
set estimate1;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
where Parameter="emot_hlth_dim2_H2018";
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);
  
data output_linear;
retain outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
set output_distracted2019_r output_jobsatis2019 ;
keep outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
run;

%let path=C:\HSPH\manuscripts\Flourishing and work outcomes\Outputs_revision;

ods csv file="&path/3A. Complete_case_emotion.csv";
proc print data=output_linear; run;
ods csv close;


*2. physical health;
Data complete;
set wellbeing;

if nmiss (of emot_hlth_dim2_H2018 phys_hlth_dim_H2018 social_WB_H2018 char_str_H2018 financ_WB2_H2018 purpose_dim2_H2018 
             race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
             elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
             work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018 
             distracted2018_r jobsatis2018 w_productive2018)>0 then delete;

%macro linear(outcome);
proc glm data=complete;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= phys_hlth_dim_H2018  
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm; 
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

data estimate2;
length outcome $50.;
set estimate1;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
where Parameter="phys_hlth_dim_H2018";
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);
  
data output_linear;
retain outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
set output_distracted2019_r output_jobsatis2019;
keep outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
run;

%let path=C:\HSPH\manuscripts\Flourishing and work outcomes\Outputs_revision;

ods csv file="&path/3B. Complete_case_physical.csv";
proc print data=output_linear; run;
ods csv close;

*3. social;
Data complete;
set wellbeing;

if nmiss (of emot_hlth_dim2_H2018 phys_hlth_dim_H2018 social_WB_H2018 char_str_H2018 financ_WB2_H2018 purpose_dim2_H2018 
             race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
             elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
             work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018 
             distracted2018_r jobsatis2018 w_productive2018)>0 then delete;

%macro linear(outcome);
proc glm data=complete;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= social_WB_H2018
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm; 
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

data estimate2;
length outcome $50.;
set estimate1;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
where Parameter="social_WB_H2018" ;
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);
  
data output_linear;
retain outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
set output_distracted2019_r output_jobsatis2019 ;
keep outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
run;

%let path=C:\HSPH\manuscripts\Flourishing and work outcomes\Outputs_revision;

ods csv file="&path/3C. Complete_case_social.csv";
proc print data=output_linear; run;
ods csv close;

*4. character;
Data complete;
set wellbeing;

if nmiss (of emot_hlth_dim2_H2018 phys_hlth_dim_H2018 social_WB_H2018 char_str_H2018 financ_WB2_H2018 purpose_dim2_H2018 
             race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
             elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
             work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018 
             distracted2018_r jobsatis2018 w_productive2018)>0 then delete;

%macro linear(outcome);
proc glm data=complete;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= char_str_H2018
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm; 
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

data estimate2;
length outcome $50.;
set estimate1;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
where Parameter="char_str_H2018";
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);
  
data output_linear;
retain outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
set output_distracted2019_r output_jobsatis2019;
keep outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
run;

%let path=C:\HSPH\manuscripts\Flourishing and work outcomes\Outputs_revision;

ods csv file="&path/3D. Complete_case_character.csv";
proc print data=output_linear; run;
ods csv close;

*5. financial;
Data complete;
set wellbeing;

if nmiss (of emot_hlth_dim2_H2018 phys_hlth_dim_H2018 social_WB_H2018 char_str_H2018 financ_WB2_H2018 purpose_dim2_H2018 
             race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
             elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
             work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018 
             distracted2018_r jobsatis2018 w_productive2018)>0 then delete;

%macro linear(outcome);
proc glm data=complete;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= financ_WB2_H2018 
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm; 
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

data estimate2;
length outcome $50.;
set estimate1;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
where Parameter="financ_WB2_H2018";
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);
  
data output_linear;
retain outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
set output_distracted2019_r output_jobsatis2019;
keep outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
run;

%let path=C:\HSPH\manuscripts\Flourishing and work outcomes\Outputs_revision;

ods csv file="&path/3E. Complete_case_finance.csv";
proc print data=output_linear; run;
ods csv close;

*6. purpose;
Data complete;
set wellbeing;

if nmiss (of emot_hlth_dim2_H2018 phys_hlth_dim_H2018 social_WB_H2018 char_str_H2018 financ_WB2_H2018 purpose_dim2_H2018 
             race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
             elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
             work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018 
             distracted2018_r jobsatis2018 w_productive2018)>0 then delete;

%macro linear(outcome);
proc glm data=complete;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= purpose_dim2_H2018 
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm; 
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

data estimate2;
length outcome $50.;
set estimate1;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
where Parameter="purpose_dim2_H2018";
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);
  
data output_linear;
retain outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
set output_distracted2019_r output_jobsatis2019;
keep outcome Parameter Estimate StdErr LowerCL UpperCL Probt;
run;

%let path=C:\HSPH\manuscripts\Flourishing and work outcomes\Outputs_revision;

ods csv file="&path/3F. Complete_case_purpose.csv";
proc print data=output_linear; run;
ods csv close;
